<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>侦听器</title>
		<script src="../js/vue.js"></script>
	</head>
	<body>
		<div id="root">
			<div>
				输入问题：<textarea v-model = "question"></textarea>
			</div>
			<div>
				<p>{{answer}}</p>
			</div>
		</div>
		
		<script type="text/javascript">
			const vm = new Vue({
				el: "#root",
				data: {
					question: '',
					answer: ''
				},
				watch: {
					// 监听 question 属性，如果其值发生变化，这个函数就会执行
					// newVal - 取新的值 ； oldVal 取旧的值
					question: function(newVal,oldVal){
						console.log('新值：' + newVal)
						console.log('旧值' + oldVal)
					}
				}
			})
		</script>
	</body>
</html>